﻿using System.Data.Entity.Core.Common.CommandTrees;
using System.Linq;
using System.Web.Http;
using Route.Web.Models;

namespace Route.Web.Controllers
{
    public class WebApiController : ApiController
    {
        private readonly RouteDB db = new RouteDB();

        [Route("api/schools")]
        public IHttpActionResult GetAllSchools()
        {
            var allSchools = db.schools.ToList();
            return Ok(allSchools);
        }

        [Route("api/classrooms")]
        public IHttpActionResult GetAllClassrooms()
        {
            var books = db.classrooms.Include("school").Select(i =>
                new { i.id, i.name, i.teacher, i.school }).ToList();

            return Ok(books);
        }

        [Route("api/activities")]
        public IHttpActionResult GetAllActivities()
        {
            var allActivities = db.activities.ToList();
            return Ok(allActivities);
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}